//
//  VipCardStateSelectViewController.m
//  fitnessmanage
//
//  Created by 众拳科技 on 2017/10/31.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//
extern NSString * const YZUpdateMenuTitleNote;

#import "VipCardStateSelectViewController.h"
#import "VipInfoTableViewCell.h"

@interface VipCardStateSelectViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong)UITableView *tableView;

@property (nonatomic, assign) NSInteger selectedCol;

@end

@implementation VipCardStateSelectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _selectedCol = 0;
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    tableView.dataSource = self;
    tableView.delegate = self;
    tableView.showsVerticalScrollIndicator = NO;
    [tableView registerClass:[VipInfoTableViewCell class] forCellReuseIdentifier:@"VipInfoTableViewCell"];
    tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    tableView.backgroundColor = BackGroundColor;
    [self.view addSubview:tableView];
    self.tableView = tableView;
    [tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(self.view);
    }];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    NSIndexPath *indexPath = [NSIndexPath indexPathForItem:_selectedCol inSection:0];
    
    [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.titleArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    VipInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"VipInfoTableViewCell"];
    cell.textLabel.text = _titleArray[indexPath.row];
    cell.textLabel.font = MidFont;
    if (indexPath.row == 0) {
        [cell setSelected:YES animated:NO];
    }
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    _selectedCol = indexPath.row;
    
    // 选中当前
    VipInfoTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
            
    // 更新菜单标题
    [[NSNotificationCenter defaultCenter] postNotificationName:YZUpdateMenuTitleNote object:self userInfo:@{@"title":cell.textLabel.text,@"col":@(self.colCount)}];
    
}

@end
